import 'package:flutter/material.dart';

class SwitchPage extends StatefulWidget {
   SwitchPage({super.key});

  @override
  State<SwitchPage> createState() => _SwitchPageState();
}

class _SwitchPageState extends State<SwitchPage> {
  //switch开关
  bool isOpen = false;

  bool isPiano = false;
  bool isGiTar = false;

  String sex = "男";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Text'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(20.0),
        child: ListView(

          children:  [
             Row(
               mainAxisAlignment: MainAxisAlignment.spaceBetween,
               children: [
               Text("打开背景音乐"),
               Switch(value: isOpen, onChanged: (value)=>changeSwitch(value))
             ],),

            Text("兴趣爱好"),
            //checkbox
            CheckboxListTile(value: isPiano, onChanged: (value)=>changePiano(value!),title: Text("钢琴"),),
            CheckboxListTile(value: isGiTar, onChanged: (value)=>changeGitar(value!),title: Text("吉他"),),

            Text("性别"),
            RadioListTile(title: Text("男"), value: "男", groupValue: sex, onChanged: (value)=> setState(() {
              sex = value!;
            })),
            RadioListTile(title: Text("女"), value: "女", groupValue: sex, onChanged: (value)=> setState(() {
              sex = value!;
            }))
          ],
        ),
      ),
    );
  }

  changeSwitch(bool value) {
    setState(() {
      isOpen = value;
    });
  }

  changePiano(bool value) {
    setState(() {
      isPiano = value;
    });
  }

  changeGitar(bool value) {
    setState(() {
      isGiTar = value;
    });
  }
}
